var that;
function Move(drag) {
    drag.onmousedown = function(e) {
        that = this
        var startX = e.clientX - this.offsetLeft;
        var startY = e.clientY - this.offsetTop;
        document.onmousemove = function(e) {
            var x = e.clientX - startX
            var y = e.clientY - startY
            if(x < 0) {
                x = 0
            }
            if(y < 0) {
                y = 0
            }
            var w = window.innerWidth || document.body.offsetWidth || document.documentElement.clientWidth
            var h = window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight
            if(x > w - that.offsetWidth) {
                x = w - that.offsetWidth
            }
            if( y > h - that.offsetHeight) {
                y = h - that.offsetHeight
            }
            that.style.left = x + 'px';
            that.style.top = y + 'px'
        }
    }
    drag.onmouseup = function() {
        document.onmousemove = null
    }
}


export default Move